package Pet.Management.common.utils;

import org.springframework.stereotype.Component;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.time.LocalDateTime;

@Component
public class CaptchaStorage {
    private final Map<String, CaptchaInfo> storage = new ConcurrentHashMap<>();
    
    private static class CaptchaInfo {
        String code;
        LocalDateTime expireTime;
        
        CaptchaInfo(String code, LocalDateTime expireTime) {
            this.code = code;
            this.expireTime = expireTime;
        }
    }
    
    public void setCaptchaCode(String uuid, String code) {
        storage.put(uuid, new CaptchaInfo(code, LocalDateTime.now().plusMinutes(2)));
    }
    
    public String getCaptchaCode(String uuid) {
        CaptchaInfo info = storage.get(uuid);
        if (info == null) {
            return null;
        }
        
        if (LocalDateTime.now().isAfter(info.expireTime)) {
            storage.remove(uuid);
            return null;
        }
        
        return info.code;
    }
    
    public void deleteCaptchaCode(String uuid) {
        storage.remove(uuid);
    }
} 